import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import { resolve } from 'path'
import UnoCSS from 'unocss/vite'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'

// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueJsx(),
    UnoCSS(),
    AutoImport({
      imports: ['vue', 'vue-router']
    }),
    Components()
  ],
  resolve: {
    alias: {
      '@': resolve(__dirname, './src')
    }
  },
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: ''
      }
    },
    devSourcemap: true
  },
  server: {
    open: true,
    proxy: {
      '/api': {
        target: 'http://www.test.com',
        changeOrigin: true
        // rewrite: (path) => path.replace(/^\/api/, ''), // 如果后端接口没有 /api 前缀，则需要去掉
      }
    }
  }
})
